package com.yoomiito.app.ui.my.angle

import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.BaseModel
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.base.AppConfig
import com.yoomiito.app.base.BaseActPresenter
import com.yoomiito.app.model.my.AnglePayResult
import com.yoomiito.app.model.my.BaseAngleInfo
import com.yoomiito.app.net.YmApi

class AnglePresenter(appConfig: AppConfig) :BaseActPresenter<AngleActivity>(appConfig){

    fun getInfo(type:Int){
        YmApi.getYmService()
                .angleBaseInfo()
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<BaseAngleInfo>(handleException()){
                    override fun onSuccess(t: BaseAngleInfo?) {
                        v.setData(t,type)
                    }

                    override fun onFail(error: ApiException?) {
                        v.dismissLoading()
                        v.finish()
                    }
                })
    }

    fun pay(psd:String){
        YmApi.getYmService()
                .payForAngle(psd)
                .compose(v.bindToLifecycle())
                .compose(XApi.getApiTransformerNoData<BaseModel<*>>())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<BaseModel<*>>(){
                    override fun onSuccess(t: BaseModel<*>?) {
                        v.payResult(true)
                    }

                    override fun onFail(error: ApiException?) {
                        v.payResult(false,error?.msg!!)

                    }

                })

    }
}